package com.yanqu.road.server.cmd.task;


import com.yanqu.road.pb.task.TaskProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.server.command.Cmd;

import java.util.List;

@Cmd(code = Protocol.S_TASK_GET_REWARD, desc = "领取任务奖励")
public class GetTaskRewardCmd extends AbstractCommand {

	private int taskId;
	private int type;
	private List<Integer> taskIdList;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		TaskProto.TaskGetRewardReqMsg reqMsg = TaskProto.TaskGetRewardReqMsg.parseFrom(packet.getBytes());
		taskId = reqMsg.getTaskId();
		taskIdList = reqMsg.getTaskIdsList();
		type = reqMsg.getType();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		if(type == 1 || type == 0){//兼容早版本，没有type字段
			player.sendPacket(Protocol.U_TASK_GET_REWARD, player.getModule(TaskModule.class).getTaskReward(taskId));
		}else if(type == 2){
			player.sendPacket(Protocol.U_TASK_GET_REWARD, player.getModule(TaskModule.class).getTaskRewards(taskIdList));
		}
	}

	@Override
	public void sendData(GamePlayer player) {

	}

}
